﻿using System;
using System.Collections.Generic;

namespace WinFormsMVC
{
    public class PropertyBag
    {
        private Dictionary<string, IPropertyBagItem> properties = new Dictionary<string, IPropertyBagItem>();

        public void Set(string key, IPropertyBagItem value)
        {
            if (properties.ContainsKey(key))
                properties[key] = value;
            else
                properties.Add(key, value);
        }

        public IPropertyBagItem this[string key]
        {
            get
            {
                return properties[key];
            }
            set
            {
                properties[key] = value;
            }
        }
    }

    public interface IPropertyBagItem
    { }

    public abstract class PropertyBagItem<T> : IPropertyBagItem
    {
        public PropertyBagItem(T value)
        {
            Value = value;
        }

        public T Value { get; set; }
    }

    public class PropertyBagStringItem : PropertyBagItem<string>
    {
        public PropertyBagStringItem(string value)
            : base(value)
        {
        }
    }

    public class PropertyBagIntItem : PropertyBagItem<int>
    {
        public PropertyBagIntItem(int value)
            : base(value)
        {
        }
    }

    public class PropertyBagDateTimeItem : PropertyBagItem<DateTime>
    {
        public PropertyBagDateTimeItem(DateTime value)
            : base(value)
        {
        }
    }
}
